﻿using System.Collections.Generic;
using System.Configuration;
using System.Web.Mvc;
using Lab3MiddleTier;

namespace NinjaLoot2.Controllers
{
    public class StoreController : Controller
    {

    	private MiddleTier _middle;
        //
        // GET: /Store/


		public StoreController()
		{
			_middle = new MiddleTier(ConfigurationManager.ConnectionStrings["BackendMySQL"].ConnectionString);
		}

		
        public ActionResult Index()
        {
            return View(_middle.GetAllFiles());
        }

		public ActionResult Browse(string SearchWord)
		{
			return View(_middle.GetFilesBySearch(SearchWord));
		}

		public ActionResult Details(int id)
		{
			return View(_middle.GetFileById(id));
		}

		[Authorize(Roles = "Member")]
		public ActionResult DownloadFile(int id)
		{
			var file = _middle.GetFileById(id);
			return File(file.FileBytes,file.Type,file.Name);
		}
    }
}
